package com.unism.util;

import java.util.HashMap;
import java.util.Map;

import com.googlecode.aviator.AviatorEvaluator;
import com.googlecode.aviator.Expression;

public class DataUtil {
	
	public static void main(String[] args) {
		Double a = DataUtil.orig2Corr(101.000000001f,"a");
		Float b = a.floatValue();
		System.out.println(b);
	}
	
	public static Double orig2Corr (Float origValue,String express){
		try{
			String expression = express;
			// 编译表达式
	        Expression compiledExp = AviatorEvaluator.compile(expression,true);
	        Map<String, Object> env = new HashMap<String, Object>();
	        env.put("a", origValue);
	        // 执行表达式
	        java.lang.Double result = (java.lang.Double) compiledExp.execute(env);
	        return result ;
		} catch (Exception e){
			String expression = "a+0";
			// 编译表达式
	        Expression compiledExp = AviatorEvaluator.compile(expression,true);
	        Map<String, Object> env = new HashMap<String, Object>();
	        env.put("a", origValue);
	        // 执行表达式
	        java.lang.Double result = (java.lang.Double) compiledExp.execute(env);
	        return result ;
		}
	}

}
